package com.xx.library.common;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    //处理RuntimeException及其子类，返回具体的异常信息给客户端
    public Result<String> handleRuntimeException(RuntimeException e) {
        return Result.error(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    //处理所有其他异常，返回通用错误信息 "系统错误，请联系管理员"
    public Result<String> handleException(Exception e) {
        return Result.error("系统错误，请联系管理员");
    }
}